﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Runtime.Serialization;
using System.ComponentModel;


namespace XMas
{
    /// <summary>
    ///  Initial node, can be only one!
    /// </summary>
    [Serializable()]
    public class AnimNode_Start : AnimationNode
    {
        /// <summary>
        /// Number of version of this subnode, used in serialization
        /// </summary>
        /// <remarks>
        /// If you add a new value to serialization, you need to increment this float
        /// This is need to have compatibility with olders version of library
        /// <see cref="WriteXml(System.Xml.XmlWriter)"/>
        /// </remarks> 
        protected const float _SerializationVersionChild = 1.0f;

        /// <summary>
        /// Constructor
        /// </summary>
        public AnimNode_Start()
        {

        }

        /// <summary>
        /// Atribute for ReflexionProperty
        /// <see cref="AnimationNode.ReflexionProperty"/>
        /// </summary>
        [Browsable(false)]
        public override string ReflexionProperty 
        {
            get { return base.ReflexionProperty; }
            set { base.ReflexionProperty = value; }
        }

        /// <summary>
        /// Atribute for Name
        /// <see cref="AnimationNode.Name"/>
        /// </summary>
        [Browsable(false)]
        public override string Name
        {
            get { return base.Name; }
            set { base.Name = value; }
        }


        # region Protected Members

        /// <summary>
        /// Initialization of node, set initial values
        /// </summary>
        /// <param name="ID">Node ID</param>
        protected override void Initialize(System.Guid ID)
        {
            base.Initialize(ID);
            _strName = "Start Node";
            AddChild("Start", 1.0f);
            _bFixedChildren = true;
             _fEditorValue = 1.0f;
            _CategoryName = "Start Nodes";
        }

        /// <summary>
        /// Internal get current value, first try to use reflexion. If no reflexion found use editor value
        /// Override with caution
        /// </summary>
        /// <returns>Value from 0 to 1</returns>
        protected override float GetValue()
        {            
            // Fixed
            return 1.0f;
        }

        #endregion


        # region Public Members

        /// <summary>
        /// Used by system when the node need to update his weight
        /// </summary>
        /// <param name="DeltaSeconds">Elapsed time</param>
        public override void UpdateWeights(double DeltaSeconds)
        {
            _fCurrentValue = GetValue();
            _fEditorValue = _fCurrentValue;
            _animNodeItemList[0]._fLocalWeigth = _fCurrentValue;
        }


        /// <summary>
        /// Used by system after the node update his weight
        /// </summary>
        /// <param name="elapsedTime"></param>
        public override void PostUpdateWeights(TimeSpan elapsedTime)
        {
        }

        /// <summary>
        /// EDITOR EVENT: Called by editor when slider move
        /// </summary>
        /// <param name="iNewValue">Value is between 0 and 100</param>
        public override void HandleSliderMove(int iNewValue)
        {
        }


        #endregion
        

        #region Load/Save XML

        /// <summary>
        /// Function to write in XML format, if you overwrite you must call base class first
        /// </summary>
        /// <remarks>
        /// Be carefully with the save order, it must be the same that read order!!
        /// </remarks>
        /// <param name="writer">Writer to store data</param>
        public override void WriteXml(XmlWriter writer)
        {
            base.WriteXml(writer);

            writer.WriteElementString("SerializationVersionChild", _SerializationVersionChild.ToString(new System.Globalization.CultureInfo("en-US")));            
        }

        /// <summary>
        /// Function to read xml format, if you overwrite you must call base class first
        /// </summary>
        /// <remarks>
        /// Be carefully with the read order, it must be the same that save order!!
        /// </remarks>
        /// <param name="reader">Reader to retrieve data</param>
        public override void ReadXml(XmlReader reader)
        {
            base.ReadXml(reader);

            float SerializationVersionChild = reader.ReadElementContentAsFloat("SerializationVersionChild", reader.NamespaceURI);            
        }

        #endregion


    }
}
